package org.ting.e_commerce.model;

import lombok.Data;
import org.ting.e_commerce.enums.ResultStatus;
/**
 * 统一返回信息实体类
 * @param <T> body
 */

public class Result<T> {
    //状态码 200 成功  0 错误  -1 未登录
    private ResultStatus code;

    //错误信息
    private String errMsg;

    //返回数据
    private T data;


    public static <T> Result<T> success(T data) {
        Result<T> result = new Result<>();
        result.setCode(ResultStatus.SUCCESS);
        result.setErrMsg("");
        result.setData(data);
        return result;
    }

    public static <T> Result<T> fail(String errMsg) {
        Result<T> result = new Result<>();
        result.setCode(ResultStatus.FAIL);
        result.setErrMsg(errMsg);
        result.setData(null);
        return result;
    }


    public ResultStatus getCode() {
        return code;
    }

    public void setCode(ResultStatus code) {
        this.code = code;
    }

    public String getErrMsg() {
        return errMsg;
    }

    public void setErrMsg(String errMsg) {
        this.errMsg = errMsg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
